<?php
/**
 * Created by PhpStorm.
 * User: gaochaolyf
 * Date: 16/5/17
 * Time: 下午4:40
 */

namespace api\Model;

use Think\Model;

class OrderEntityModel extends Model
{
    function __construct() {
        $this->model = M('OrderEntity');
    }

    public function getOrderList($field = array('*'), $condition = array(), $page = 1, $pergage = 10,$order = 'add_at desc') {

        $data = $this->model->where($condition)->field($field)->page($page, $pergage)->order($order)->select();
       foreach ($data as $key=>$value){
           $data[$key]['allnum'] = $this->model->where($condition)->count();
       }
        $data = $data ? $data : array();
        return $data;
    }

    public function getOneOrder($field = array('*'), $condition = array()) {
        $data = $this->model->where($condition)->field($field)->find();
        $data = $data ? $data : array();
        return $data;
    }

    public function getOrderById($order_id = 0, $field = array('*')) {
        $data = $this->model->where(array('order_id' => $order_id))->field($field)->find();
        $data = $data ? $data : array();
        return $data;
    }

    public function addOneOrder($param = array()) {
        $insert_id = $this->model->data($param)->add();
        return $insert_id;
    }


    public function updateOrder($param = array(), $condition = array()) {
        $affected = $this->model->where($condition)->setField($param);
        return $affected;
    }

    //得到订单数量

    public function ordernum($condition = array()) {
        $info = $this->model->where($condition)->select();
        return $info;
    }
}